package tool.code.generater.sampler;


import tool.code.generater.TypeMapper;
import tool.code.generater.config.JdbcConfig;
import tool.code.generater.struct.SamplerType;
import tool.code.generater.struct.TableDef;
import com.alibaba.druid.DbType;

import java.util.List;

public abstract class TableInfoSampler {
    protected final DbType dbType;
    protected TypeMapper typeMapper;
    protected JdbcConfig jdbcConfig;

    public TableInfoSampler(DbType dbType, String mappingConfigFile, JdbcConfig jdbcConfig) {
        this.dbType = dbType;
        this.jdbcConfig = jdbcConfig;
        if (mappingConfigFile == null || mappingConfigFile.isEmpty()) {
            return;
        }
        typeMapper = new TypeMapper(mappingConfigFile);
    }

    public abstract List<TableDef> getColumns();




    public static TableInfoSampler create(SamplerType samplerType, DbType dbType, String mappingConfigFile, JdbcConfig jdbcConfig) {
        if (samplerType == SamplerType.DDL) {
            return new DDLTableInfoSampler(dbType, mappingConfigFile, jdbcConfig);
        }
        if (samplerType == SamplerType.DB) {
            return new DBTableInfoSampler(dbType, mappingConfigFile, jdbcConfig);
        }
        return null;
    }
}
